<template>
  <div class="wraps">
    <div class="title">
      <img src="../../images/main/activity.png" alt>
      <span class="back" @click="backParMan()">活动详情</span>
    </div>
    <div class="clear"></div>
    <div class="nowParman" v-if="acDetails.states == 1">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >待合作</span>
      <div class="info">当前活动订单等待合作双方确认分成比例。</div>
    </div>
    <div class="nowParman" v-else-if="acDetails.states == 2">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >待审核</span>
      <div class="info">通过审核后，该活动可进行报名。</div>
    </div>
    <div class="nowParman" v-else-if="acDetails.states == 3">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >已驳回</span>
      <div class="info">当前订单被驳回，驳回原因：{{acDetails.reject}}</div>
    </div>
    <div class="nowParman" v-else-if="acDetails.states == 4">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >待报名</span>
      <div class="info">活动订单已生成，若在活动开始前24小时未达到活动最低成团人数，系统将自动取消订单。</div>
    </div>
    <div class="nowParman" v-else-if="acDetails.states == 5">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >已成团 </span>
      <div class="info">当前报名人数已经成团，请等待活动开始。</div>
    </div>
    <div class="nowParman" v-else-if="acDetails.states == 6">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >待签到</span>
      <div class="info">通过审核后，该活动可进行报名。</div>
    </div>
    <div class="nowParman" v-else-if="acDetails.states == 7">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >已结束</span>
      <div class="info">当前活动已圆满结束，结算后您可以通过财务进行提现操作。</div>
    </div>
    <div class="nowParman" v-else>
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >已关闭</span>
      <div class="info">当前活动已超过报名时间，报名人数未达到最低成团邀请，活动已被系统关闭。</div>
    </div>
    <div class="mans">
      <span>活动信息</span>
    </div>
    <div class="body">
      <div class="list">
        <ul class="listBody">
          <li>
            <span class="listTitle">订单编号：</span>
            <span class="listValue">{{acDetails.activityNo}}</span>
          </li>
          <li>
            <span class="listTime">订单时间：</span>
            <span class="listValue">{{ setDate(acDetails.releaseTime) + ' '+ setTime(acDetails.releaseTime) }}</span>
          </li>
        </ul>
        <div class="clear"></div>
        <ul class="listBody">
          <li>
            <span class="listTitle">活动开始时间：</span>
            <span class="listValue">{{setDate(acDetails.activityTime)+' '+setTime(acDetails.activityTime)}}</span>
          </li>
          <li>
            <span class="listTime">报名截止时间：</span>
            <span class="listValue">{{setDate(acDetails.closingTime)+' '+setTime( acDetails.closingTime)}}</span>
          </li>
        </ul>
        <div class="clear"></div>
        <ul class="listBody">
          <li>
            <span class="listTitle">活动可参与人数：</span>
            <span class="listValue">{{acDetails.participateMin}}-{{acDetails.participateMax}}人</span>
          </li>
          <li>
            <span class="listTime">当前报名人数：</span>
            <span class="listValue">{{acDetails.signCount}}人 ({{Number(acDetails.participateMin) > Number(acDetails.signCount) ? '还差'+ Number(acDetails.participateMin - acDetails.signCount) + '人成团' : '已成团' }})</span>
          </li>
        </ul>
        <div class="clear"></div>
        <ul class="listBody">
          <li>
            <span class="listTitle">客户报名费：</span>
            <span class="listValue">{{acDetails.activityPrice}}元/人</span>
          </li>
          <li>
            <span class="listTime">活动成分：</span>
            <span class="listValue">服务商{{acDetails.serviceCommission}}% : 门店{{acDetails.partnerCommission}}%</span>
          </li>
        </ul>
        <div class="clear"></div>
        <ul class="listBody">
          <li>
            <span class="listTitle">活动地址：</span>
            <span class="listValue" :title="acDetails.activityAddress">{{acDetails.activityAddress}}</span>
          </li>
          <li>
            <span class="listTime">门店名称：</span>
            <span class="listValue" :title="acDetails.storeName">{{acDetails.storeName}}</span>
          </li>
        </ul>
        <div class="clear"></div>

        <ul class="listBody">
          <li>
            <span class="listTitle">场地类型：</span>
            <span class="listValue">{{acDetails.roomType}}</span>
          </li>
          <li>
            <span class="listTime">适用年龄：</span>
            <span class="listValue">{{acDetails.age + '岁' || '-'}}</span>
          </li>
        </ul>
        <div class=""></div>
      </div>
    </div>
    <!-- <div class="examine" v-if="acDetails.states == 2">
      <div>通过审核</div>
      <div @click="reject()">驳回</div>
    </div> -->
   <!--  <div class="examine" v-if="acDetails.states == 6">
      <div @click="verification">核销</div>
      <div @click="reject()">驳回</div>
    </div> -->
    <div class="examine" v-if="acDetails.states == 1">
      <div @click="verify">确认合作</div>
      <div @click="reject">驳回</div>
    </div>
      <div class="table" v-if="acDetails.states == 4 || acDetails.states == 5 || acDetails.states == 6 || acDetails.states == 7 || acDetails.states == 8">
        <div class="sthead">
          <div>头像</div>
          <div>微信昵称</div>
          <div>手机号</div>
          <div>报名费(元)</div>
          <div>交易单号</div>
          <div class="update">报名时间</div>
          <div>状态</div>
        </div>
        <div class="tlists">
          <div class="tlist" style="    text-align: center;
    display: block;
    height: 60px;
    line-height: 60px;" v-if="list.length == 0">
            暂无数据
          </div>
          <div class="tlist" v-else v-for="( item, index ) in list">
            <div >
              <img class="tlogo" :src="item.user_img || require('../../images/main/tlogo.png')" alt>
            </div>
            <div>{{ item.nick_name }}</div>
            <div>{{ item.user_phone }}</div>
            <div>{{ item.pay_price }}</div>
            <div style="max-width:15%;"><span style="display:inline-block;overflow:hidden;word-wrap: break-word;">{{ item.order_num }}</span></div>
            <div class="update">
              <div class="day">{{ setDate( item.pay_time )}} {{setTime ( item.pay_time )}}</div>
            </div>
            <div>
              
              <span v-if="item.qian && acDetails.states != 5">已签到</span>
              <el-button @click="verification( item )" type="primary" v-else-if="acDetails.states == 6">
                活动签到
              </el-button>

            </div>
          </div>
        </div>
      </div>

      <div class="sign" ref="sign">
        <el-form class="form" ref="form" label-width="100px">
          <el-form-item label="手机号:">
            <!-- <el-input :value="15822888888"></el-input> -->
            <div style="text-align:left">{{ currentItem.phone }}</div>
          </el-form-item>
          <el-form-item label="签到码:">
            <el-input placeholder="请输入签到码" v-model="signCode" @input="inputCode"></el-input>
          </el-form-item>
        </el-form>
        <el-button class="el-form-bttuon-primary"  type="primary" @click="verificationSubmit">
          确定
        </el-button>
      </div>
  </div>
</template>

<style type="text/scss" lang="scss" scoped>
  .wraps {
    .sign {
      display: none;
      text-align: center;
      padding-top: 50px;
      width: 300px;
      margin: 0 auto;
    }
    /deep/ .sign input{
      border-radius: 0;
    }
  }
  /deep/ .layui-layer-title{
    padding: 0;
    margin: 0 60px;
    text-align: center;
    background-color: #fff;
  }
  /deep/ .el-form-bttuon-primary{
    border-radius: 0;
    background: #4B74FF;
    width: 160px;
    border: 0 none;
  }
</style>

<script>
import Global from '../tool/Global.vue'
import axios from 'axios'
import qs from 'qs' // 将请求转换成form 表单提交形式
export default {
  created () {
    axios.post (
      `${this.$store.state.baseUrl}/partner/api/activity/selectSignList`,
      qs.stringify ({
        activityId: this.$route.query.id
      })
    ).then ( response => {
      let res = response.data;
      if ( res.code == 0 ) {
        this.list = res.data;
      }
      // console.log ( response );
    });
  },
  data() {
    return {
      acDetails: {},
      signCode: '',
      list: [],
      currentItem: {
        phone: 0
      }
    };
  },
  methods: {
    inputCode(){
      let _this = this;
      setTimeout (() => {
        _this.signCode = isNaN ( _this.signCode ) ? 0 : _this.signCode.toString().replace ( /\.|-/img, '' );
      }, 10 );
    },
    verificationSubmit() {
      let _this = this;
      axios.post (
        `${_this.$store.state.baseUrl}/partner/api/activity/signActivity`,
        qs.stringify({
          id: Number ( _this.$route.query.id ),
          phone: this.currentItem.phone,
          code: this.signCode
        })
      ).then ( function (res) {
        if(res.data.code == 0) {
          _this.$alert ( '签到成功' ).then ( () => {
          _this.$router.back ( -1 );
          layer.close(layer.index);
        });
        }else{
          _this.$alert ( res.data.msg )
        }
      });
    },
    verification( obj ) {
      this.currentItem.phone = obj.user_phone;
      layer.open ({
        title: '活动签到',
        type: 1,
        zIndex: 1,
        area: [ '440px', '300px' ],
        content: $ ( this.$refs.sign ),
        end () {
          // this.$refs.sign.style.display = 'none';
        }
      });
    },
    // 确认合作
    verify() {
      let _this = this;
      axios.post (
        `${_this.$store.state.url}/activity/updateStates`,
        qs.stringify({
          id: Number ( _this.$route.query.id ),
          states: 2
        })
      ).then ( function () {
        _this.$alert ( '合作已确认' ).then ( () => {
          _this.$router.back ( -1 );
        });
      });
    },
    // 驳回
    reject() {
      let _this = this;
        this.$prompt('驳回原因', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({ value }) => {
          axios.post (
            `${_this.$store.state.url}/activity/rejectActivity`,
            qs.stringify({
              id: Number ( _this.$route.query.id ),
              reject: value
            })
          ).then ( function () {
            _this.$alert ( '成功驳回' ).then ( () => {
              _this.$router.back ( -1 );
            });
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          });
        });
    },

    backParMan: function() {
      this.$router.push({
        path: "/main/activity",
        name: "activity"
      });
    },
    /**
     * 获取活动详情
     */
    getAcDetail: function () {
      let id = this.$route.query.id;
      let that = this
      axios({
          method: 'post',
          url:`${that.$store.state.url}/activity/selectDateils`,
            data:qs.stringify({id:id})
      }).then(res => {
            console.log(res)
          if (res.data.code == 0) {
            that.acDetails = res.data.data
          } else {
            alert(res.msg);
          }
        }).catch ( res=> {
          alert('系统错误!')
        })
    },
    /**
     * 根据时间毫秒数 返回年月日
     */
    setDate: function (str) {
        let times = new Date(str)
        return `${times.getFullYear()}-${times.getMonth() + 1 < 10 ? '0' + (times.getMonth() + 1) : times.getMonth() + 1 }-${times.getDate() < 10 ? '0' + times.getDate() : times.getDate()}`
    },
    /**
     * 根据时间毫秒数 返回时分秒
     */
    setTime: function (str) {
        let times = new Date(str)
        return `${times.getHours() < 10 ? '0' + times.getHours() : times.getHours()}:${times.getMinutes() < 10 ? '0' + times.getMinutes() : times.getMinutes()}:${times.getSeconds() < 10 ? '0' + times.getSeconds() : times.getSeconds()}`
    },

  },
  mounted () {
    this.getAcDetail()
  }
};
</script>
<style scoped>
.wraps {
  padding: 68px 136px;
  background: rgb(236, 238, 243);
}
.address {
  display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
width: 300px;
}
.nowParman {
  margin-top: 37px;
  margin-left: 48px;
}
.nowParman span {
  font-size: 18px;
  font-weight: bold;
}
.nows {
  color: #d81e06;
}
.info {
  margin-top: 19px;
  margin-bottom: 35px;
  height: 20px;
  line-height: 20px;
  font-size:14px;
  color:#4a4a4a;
}
.title {
  height: 33px;
  line-height: 33px;
  font-size: 24px;
  font-family: PingFangSC-Medium;
  font-weight: bold;
}
.title span {
  float: left;
}
.title img {
  width: 28px;
  height: 26px;
  float: left;
  padding-top: 5px;
  margin-right: 10px;
}
.title .right {
  width: 11px;
  height: 18px;
  padding-top: 9px;
  margin-left: 5px;
  margin-right: 6px;
}
.body {
  background: white;
  border: 1px solid #dddddd;
  /* width: 1492px; */
  height: 415px;
  margin-top: -1px;
  /* margin-left: 45px; */
  /* padding-left: 139px; */
  width: 100%;
  padding-top: 63px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}
.mans {
  background: #e0eefe;
  border: 1px solid #dddddd;
  /* width: 1490px; */
  height: 67px;
  /* margin-left: 45px; */
}
.mans span {
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #000000;
  letter-spacing: 0.02px;
  text-align: left;
  font-weight: bold;
  line-height: 70px;
  margin-left: 39px;
  display: inline-block;
  width: 74px;
  text-align: right;
}
.listBody {
  /* width: 1376px; */
  width: 90%;
  margin: 0 auto;
  display: block;
}
.listValue {
  margin-left: 25px;
  /* width: 516px; */
  float: left;
  display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
width: 55%;
line-height: 20px;
}
.listBody li {
  float: left;
  width: 50%;
}
.listBody li span {
  float: left;
}
.listBody li .listTitle {
  display: inline-block;
  width: 146px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #727272;
  letter-spacing: 0.02px;
  text-align: right;
  font-weight: bold;
}
.listTime {
  display: inline-block;
  width: 128px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #727272;
  letter-spacing: 0.02px;
  text-align: right;
  font-weight: bold;
}
.listValue {
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #000000;
  letter-spacing: 0.02px;
  text-align: left;
  font-weight: bold;
}
.list .clear {
  height: 33px;
}
.endDetail {
  position: relative;
}
.imgsBuy {
  background: white;
  box-shadow: 0 1px 5px 0 #b8b7b9;
  width: 320px;
  height: 205px;
  position: absolute;
  left: 170px;
}
.wrap {
  padding: 68px 136px;
  width: 100%;
}
.title {
  height: 33px;
  line-height: 33px;
  font-size: 24px;
  font-family: PingFangSC-Medium;
  font-weight: bold;
}
.title img {
  width: 28px;
  height: 26px;
  float: left;
  padding-top: 5px;
  margin-right: 10px;
}
.screen {
  width: 1490px;
  height: 60px;
  background: #f6f6f6;
  margin-left: 38px;
  margin-top: 24px;
  line-height: 60px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #888888;
}
.screen img {
  float: left;
  width: 27px;
  height: 27px;
  margin-left: 10px;
  margin-top: 16px;
  margin-right: 18px;
}
.sel {
  margin-top: 27px;
  padding-left: 38px;
  height: 40px;
  line-height: 40px;
}
.sel .txt {
  float: left;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #000000;
  font-weight: bold;
  width: 73px;
}
.sel input {
  float: left;
  background: #ffffff;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 317px;
  height: 40px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #888888;
  margin-left: 17px;
  text-align: center;
  box-sizing: border-box;
}
.btn {
  float: left;
  color: #fff;
  background: #4B74FF;
  border: 1px solid #4B74FF;
  width: 140px;
  height: 38px;
  text-align: center;
  margin-left: 37px;
}
.table {
  width: 100%;
  margin-top: 43px;
  /* margin-left: 45px; */
}
.table .sthead {
  border-bottom: 1px solid #dddddd;
  height: 67px;
  font-family: PingFangSC-Medium;
  font-size: 20px;
  color: #000000;
  line-height: 67px;
  font-weight: bold;
  background: #e0eefe;
  width: 100%;
  display: flex;
}
.parname {
  width: 187px;
}
.parname img {
  margin: 18px 0 0 9px;
  width: 170px;
  height: 90px;
  float: left;
}
.sthead > div {
  float: left;
  text-align: center;
  box-sizing: border-box;
  flex: 1;
}
.parnum {
  width: 149px;
}
.phone {
  width: 162px;
}
.area {
  width: 137px;
}
.monkey {
  width: 147px;
}
.date {
  width: 140px;
}
.update {
  width: 184px;
}
.state {
  width: 142px;
}
.table .thead {
  text-align: left;
  font-family: PingFangSC-Medium;
  font-size: 24px;
  color: #000000;
  height: 69px;
  line-height: 69px;
  padding-left: 15px;
  background: #e0eefe;
  border: 1px solid #dddddd;
  box-sizing: border-box;
  font-weight: bold;
}
.addpar {
  background: #f6f6f6;
  border: 1px solid #4B74FF;
  border-radius: 2px;
  width: 107px;
  height: 33px;
  float: right;
  font-family: PingFangSC-Regular;
  font-size: 14px;
  line-height: 33px;
  margin-top: 17px;
  margin-right: 20px;
  color: #4B74FF;
  cursor: pointer;
}
.add {
  width: 18px;
  height: 18px;
  float: left;
  margin: 8px;
}
.tlist > div {
  height: 142px;
  flex: 1;

display: flex;
    justify-content:center;
    align-items:Center;
}
.tlist .update {
  line-height: 25px;
  height: 142px;
}
.day,
.time {
  height: 25px;
  line-height: 25px;
  margin-top: -20px;
}
.ctrl {
  width: 242px;
}
.tlist {
  height: 142px;
  /* line-height: 142px; */
  width: 100%;
  display: flex;
}
.lastlist {
  border-right: 1px solid #ddd;
}
.tlist > div {
  float: left;
  text-align: center;
  box-sizing: border-box;
}
.tlist:last-of-type {
  background: white;
  border-bottom: 1px solid #ddd;
}
.ctrl ul {
  width: 179px;
  padding: 18px 19px 20px 31px;
  height: 104px;
}
.ctrl ul li {
  float: left;
  width: 72px;
  height: 25px;
  line-height: 25px;
  text-align: center;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #4B74FF;
  margin-top: 15px;
  font-weight: bold;
  cursor: pointer;
}
.ctrl ul li:nth-of-type(2n) {
  margin-left: 35px;
}
.ctrl .firli {
  margin-top: 0px;
}
.clear {
  clear: both;
}
.examine {
  height: 54px;
  line-height: 54px;
  text-align: center;
  margin-top: 66px;
}
.examine > div {
  width: 254px;
  height: 54px;
  text-align: center;
  line-height: 54px;
  margin-left: 66px;
  font-size:18px;
  color:#ffffff;
  font-weight: bold;
  display: inline-block;
  background:#4B74FF;
}
.examine :first-child {
  margin-left: 0;
}
</style>
